package cn.edu.pet.servlet.user;

import cn.edu.pet.entity.User;
import cn.edu.pet.repo.UserRepo;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/person/update")
public class PersonUpdateServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String id = req.getParameter("id");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String tel = req.getParameter("tel");
        String gender = req.getParameter("gender");
        String address = req.getParameter("address");
        User user = new User();
        user.setUsername(username);
        user.setId(Integer.valueOf(id));
        user.setPassword(password);
        user.setTel(tel);
        user.setGender(gender);
        user.setAddress(address);
        UserRepo.getInstance().updateUser(user);
        resp.sendRedirect("/person.html");
    }
}
